//
//  DetailsPageOfCellOfCollectionViewOfService.m
//  FreeTravel
//
//  Created by 徐康 on 16/9/9.
//  Copyright © 2016年 KX. All rights reserved.
#import "WebViewOfCommendViewController.h"
#import "CellOfDetailsPageOfCellOfCollectionViewOfService.h"
#import "FreeTravelMacro.h"
#import "DetailsPageOfCellOfCollectionViewOfService.h"
#import "FreeTravelNetwork.h"
#import "ServiceModel.h"
@interface DetailsPageOfCellOfCollectionViewOfService ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) ServiceModel *model;
@end

@implementation DetailsPageOfCellOfCollectionViewOfService

- (void)viewDidLoad {
    [super viewDidLoad];
    [self handleData];
    [self createTableView];
}
- (void)createTableView{
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-115) style:UITableViewStylePlain];
    [self.view addSubview:self.tableView];
    self.tableView.delegate = self;
    self.tableView.dataSource  = self;
    [self.tableView registerClass:[CellOfDetailsPageOfCellOfCollectionViewOfService class] forCellReuseIdentifier:@"CellOfDetailsPageOfCellOfCollectionViewOfService"];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.model.data.list.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    CellOfDetailsPageOfCellOfCollectionViewOfService *cell = [tableView dequeueReusableCellWithIdentifier:@"CellOfDetailsPageOfCellOfCollectionViewOfService"];
    cell.model = self.model.data.list[indexPath.row];
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    WebViewOfCommendViewController *vc = [[WebViewOfCommendViewController alloc]init];
    ServiceListModel *model = self.model.data.list[indexPath.row];
    vc.url = model.url;
    NSLog(@"%@",vc.url);
    [self.navigationController pushViewController:vc animated:YES];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 120;
}
- (void)handleData{
    
    if (self.type) {
        [FreeTravelNetwork GET:[NSString stringWithFormat:@"http://open.qyer.com/qyer/discount/zk/search_list?client_id=qyer_ios&client_secret=cd254439208ab658ddf9&count=20&order=0&page=1&track_app_channel=App%%2520Store&track_app_version=7.0.1&track_device_info=iPhone%%25205s&track_deviceid=E9CA001A-5603-4CA8-B2EA-2BE34F691AC6&track_os=ios%%25209.3.4&type1=%ld&v=1",self.type] andBody:nil andHeader:nil andResponse:ZWYJSON andSuccessBlock:^(id result) {
            
            self.model = [ServiceModel modelWithDic:result];
            [self.tableView reloadData];
        } andFailureBlock:^(NSError *error) {
            
        }];
    }
    if (self.string) {
        [FreeTravelNetwork GET:[NSString stringWithFormat:@"http://open.qyer.com/qyer/discount/zk/search_list?client_id=qyer_ios&client_secret=cd254439208ab658ddf9&count=20&keyword=%@&order=0&page=1&track_app_channel=App%%2520Store&track_app_version=7.0.1&track_device_info=iPhone%%25205s&track_deviceid=E9CA001A-5603-4CA8-B2EA-2BE34F691AC6&track_os=ios%%25209.3.4&v=1",self.string] andBody:nil andHeader:nil andResponse:ZWYJSON andSuccessBlock:^(id result) {
            
            self.model = [ServiceModel modelWithDic:result];
            [self.tableView reloadData];
        } andFailureBlock:^(NSError *error) {
            
        }];
    }
    [FreeTravelNetwork GET:@"http://open.qyer.com/qyer/discount/zk/hot_poi?client_id=qyer_ios&client_secret=cd254439208ab658ddf9&count=20&page=1&track_app_channel=App%2520Store&track_app_version=7.0.1&track_device_info=iPhone%25205s&track_deviceid=E9CA001A-5603-4CA8-B2EA-2BE34F691AC6&track_os=ios%25209.3.4&v=1" andBody:nil andHeader:nil andResponse:ZWYJSON andSuccessBlock:^(id result) {
        
    } andFailureBlock:^(NSError *error) {
        
    }];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
